


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > PacManSprites</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.sprite</a>
</div>

<h1>Coverage Summary for Class: PacManSprites (nl.tudelft.jpacman.sprite)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">PacManSprites</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/10)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/25)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.sprite;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.io.IOException;
<i class="no-highlight">4</i>&nbsp;import java.util.HashMap;
<i class="no-highlight">5</i>&nbsp;import java.util.Map;
<i class="no-highlight">6</i>&nbsp;
<i class="no-highlight">7</i>&nbsp;import nl.tudelft.jpacman.PacmanConfigurationException;
<i class="no-highlight">8</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
<i class="no-highlight">9</i>&nbsp;import nl.tudelft.jpacman.npc.ghost.GhostColor;
<i class="no-highlight">10</i>&nbsp;
<i class="no-highlight">11</i>&nbsp;/**
<i class="no-highlight">12</i>&nbsp; * Sprite Store containing the classic Pac-Man sprites.
<i class="no-highlight">13</i>&nbsp; *
<i class="no-highlight">14</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">15</i>&nbsp; */
<b class="nc"><i class="no-highlight">16</i>&nbsp;public class PacManSprites extends SpriteStore {</b>
<i class="no-highlight">17</i>&nbsp;
<i class="no-highlight">18</i>&nbsp;    /**
<i class="no-highlight">19</i>&nbsp;     * The sprite files are vertically stacked series for each direction, this
<i class="no-highlight">20</i>&nbsp;     * array denotes the order.
<i class="no-highlight">21</i>&nbsp;     */
<b class="nc"><i class="no-highlight">22</i>&nbsp;    private static final Direction[] DIRECTIONS = {</b>
<i class="no-highlight">23</i>&nbsp;        Direction.NORTH,
<i class="no-highlight">24</i>&nbsp;        Direction.EAST,
<i class="no-highlight">25</i>&nbsp;        Direction.SOUTH,
<i class="no-highlight">26</i>&nbsp;        Direction.WEST
<i class="no-highlight">27</i>&nbsp;    };
<i class="no-highlight">28</i>&nbsp;
<i class="no-highlight">29</i>&nbsp;    /**
<i class="no-highlight">30</i>&nbsp;     * The image size in pixels.
<i class="no-highlight">31</i>&nbsp;     */
<i class="no-highlight">32</i>&nbsp;    private static final int SPRITE_SIZE = 16;
<i class="no-highlight">33</i>&nbsp;
<i class="no-highlight">34</i>&nbsp;    /**
<i class="no-highlight">35</i>&nbsp;     * The amount of frames in the pacman animation.
<i class="no-highlight">36</i>&nbsp;     */
<i class="no-highlight">37</i>&nbsp;    private static final int PACMAN_ANIMATION_FRAMES = 4;
<i class="no-highlight">38</i>&nbsp;
<i class="no-highlight">39</i>&nbsp;    /**
<i class="no-highlight">40</i>&nbsp;     * The amount of frames in the pacman dying animation.
<i class="no-highlight">41</i>&nbsp;     */
<i class="no-highlight">42</i>&nbsp;    private static final int PACMAN_DEATH_FRAMES = 11;
<i class="no-highlight">43</i>&nbsp;
<i class="no-highlight">44</i>&nbsp;    /**
<i class="no-highlight">45</i>&nbsp;     * The amount of frames in the ghost animation.
<i class="no-highlight">46</i>&nbsp;     */
<i class="no-highlight">47</i>&nbsp;    private static final int GHOST_ANIMATION_FRAMES = 2;
<i class="no-highlight">48</i>&nbsp;
<i class="no-highlight">49</i>&nbsp;    /**
<i class="no-highlight">50</i>&nbsp;     * The delay between frames.
<i class="no-highlight">51</i>&nbsp;     */
<i class="no-highlight">52</i>&nbsp;    private static final int ANIMATION_DELAY = 200;
<i class="no-highlight">53</i>&nbsp;
<i class="no-highlight">54</i>&nbsp;    /**
<i class="no-highlight">55</i>&nbsp;     * @return A map of animated Pac-Man sprites for all directions.
<i class="no-highlight">56</i>&nbsp;     */
<i class="no-highlight">57</i>&nbsp;    public Map&lt;Direction, Sprite&gt; getPacmanSprites() {
<b class="nc"><i class="no-highlight">58</i>&nbsp;        return directionSprite(&quot;/sprite/pacman.png&quot;, PACMAN_ANIMATION_FRAMES);</b>
<i class="no-highlight">59</i>&nbsp;    }
<i class="no-highlight">60</i>&nbsp;
<i class="no-highlight">61</i>&nbsp;    /**
<i class="no-highlight">62</i>&nbsp;     * @return The animation of a dying Pac-Man.
<i class="no-highlight">63</i>&nbsp;     */
<i class="no-highlight">64</i>&nbsp;    public AnimatedSprite getPacManDeathAnimation() {
<b class="nc"><i class="no-highlight">65</i>&nbsp;        String resource = &quot;/sprite/dead.png&quot;;</b>
<i class="no-highlight">66</i>&nbsp;
<b class="nc"><i class="no-highlight">67</i>&nbsp;        Sprite baseImage = loadSprite(resource);</b>
<b class="nc"><i class="no-highlight">68</i>&nbsp;        AnimatedSprite animation = createAnimatedSprite(baseImage, PACMAN_DEATH_FRAMES,</b>
<i class="no-highlight">69</i>&nbsp;            ANIMATION_DELAY, false);
<b class="nc"><i class="no-highlight">70</i>&nbsp;        animation.setAnimating(false);</b>
<i class="no-highlight">71</i>&nbsp;
<b class="nc"><i class="no-highlight">72</i>&nbsp;        return animation;</b>
<i class="no-highlight">73</i>&nbsp;    }
<i class="no-highlight">74</i>&nbsp;
<i class="no-highlight">75</i>&nbsp;    /**
<i class="no-highlight">76</i>&nbsp;     * Returns a new map with animations for all directions.
<i class="no-highlight">77</i>&nbsp;     *
<i class="no-highlight">78</i>&nbsp;     * @param resource
<i class="no-highlight">79</i>&nbsp;     *            The resource name of the sprite.
<i class="no-highlight">80</i>&nbsp;     * @param frames
<i class="no-highlight">81</i>&nbsp;     *            The number of frames in this sprite.
<i class="no-highlight">82</i>&nbsp;     * @return The animated sprite facing the given direction.
<i class="no-highlight">83</i>&nbsp;     */
<i class="no-highlight">84</i>&nbsp;    private Map&lt;Direction, Sprite&gt; directionSprite(String resource, int frames) {
<b class="nc"><i class="no-highlight">85</i>&nbsp;        Map&lt;Direction, Sprite&gt; sprite = new HashMap&lt;&gt;();</b>
<i class="no-highlight">86</i>&nbsp;
<b class="nc"><i class="no-highlight">87</i>&nbsp;        Sprite baseImage = loadSprite(resource);</b>
<b class="nc"><i class="no-highlight">88</i>&nbsp;        for (int i = 0; i &lt; DIRECTIONS.length; i++) {</b>
<b class="nc"><i class="no-highlight">89</i>&nbsp;            Sprite directionSprite = baseImage.split(0, i * SPRITE_SIZE, frames</b>
<i class="no-highlight">90</i>&nbsp;                * SPRITE_SIZE, SPRITE_SIZE);
<b class="nc"><i class="no-highlight">91</i>&nbsp;            AnimatedSprite animation = createAnimatedSprite(directionSprite,</b>
<i class="no-highlight">92</i>&nbsp;                frames, ANIMATION_DELAY, true);
<b class="nc"><i class="no-highlight">93</i>&nbsp;            animation.setAnimating(true);</b>
<b class="nc"><i class="no-highlight">94</i>&nbsp;            sprite.put(DIRECTIONS[i], animation);</b>
<i class="no-highlight">95</i>&nbsp;        }
<i class="no-highlight">96</i>&nbsp;
<b class="nc"><i class="no-highlight">97</i>&nbsp;        return sprite;</b>
<i class="no-highlight">98</i>&nbsp;    }
<i class="no-highlight">99</i>&nbsp;
<i class="no-highlight">100</i>&nbsp;    /**
<i class="no-highlight">101</i>&nbsp;     * Returns a map of animated ghost sprites for all directions.
<i class="no-highlight">102</i>&nbsp;     *
<i class="no-highlight">103</i>&nbsp;     * @param color
<i class="no-highlight">104</i>&nbsp;     *            The colour of the ghost.
<i class="no-highlight">105</i>&nbsp;     * @return The Sprite for the ghost.
<i class="no-highlight">106</i>&nbsp;     */
<i class="no-highlight">107</i>&nbsp;    public Map&lt;Direction, Sprite&gt; getGhostSprite(GhostColor color) {
<b class="nc"><i class="no-highlight">108</i>&nbsp;        assert color != null;</b>
<i class="no-highlight">109</i>&nbsp;
<b class="nc"><i class="no-highlight">110</i>&nbsp;        String resource = &quot;/sprite/ghost_&quot; + color.name().toLowerCase()</b>
<i class="no-highlight">111</i>&nbsp;            + &quot;.png&quot;;
<b class="nc"><i class="no-highlight">112</i>&nbsp;        return directionSprite(resource, GHOST_ANIMATION_FRAMES);</b>
<i class="no-highlight">113</i>&nbsp;    }
<i class="no-highlight">114</i>&nbsp;
<i class="no-highlight">115</i>&nbsp;    /**
<i class="no-highlight">116</i>&nbsp;     * @return The sprite for the wall.
<i class="no-highlight">117</i>&nbsp;     */
<i class="no-highlight">118</i>&nbsp;    public Sprite getWallSprite() {
<b class="nc"><i class="no-highlight">119</i>&nbsp;        return loadSprite(&quot;/sprite/wall.png&quot;);</b>
<i class="no-highlight">120</i>&nbsp;    }
<i class="no-highlight">121</i>&nbsp;
<i class="no-highlight">122</i>&nbsp;    /**
<i class="no-highlight">123</i>&nbsp;     * @return The sprite for the ground.
<i class="no-highlight">124</i>&nbsp;     */
<i class="no-highlight">125</i>&nbsp;    public Sprite getGroundSprite() {
<b class="nc"><i class="no-highlight">126</i>&nbsp;        return loadSprite(&quot;/sprite/floor.png&quot;);</b>
<i class="no-highlight">127</i>&nbsp;    }
<i class="no-highlight">128</i>&nbsp;
<i class="no-highlight">129</i>&nbsp;    /**
<i class="no-highlight">130</i>&nbsp;     * @return The sprite for the
<i class="no-highlight">131</i>&nbsp;     */
<i class="no-highlight">132</i>&nbsp;    public Sprite getPelletSprite() {
<b class="nc"><i class="no-highlight">133</i>&nbsp;        return loadSprite(&quot;/sprite/pellet.png&quot;);</b>
<i class="no-highlight">134</i>&nbsp;    }
<i class="no-highlight">135</i>&nbsp;
<i class="no-highlight">136</i>&nbsp;    /**
<i class="no-highlight">137</i>&nbsp;     * Overloads the default sprite loading, ignoring the exception. This class
<i class="no-highlight">138</i>&nbsp;     * assumes all sprites are provided, hence the exception will be thrown as a
<i class="no-highlight">139</i>&nbsp;     * {@link RuntimeException}.
<i class="no-highlight">140</i>&nbsp;     *
<i class="no-highlight">141</i>&nbsp;     * {@inheritDoc}
<i class="no-highlight">142</i>&nbsp;     */
<i class="no-highlight">143</i>&nbsp;    @Override
<i class="no-highlight">144</i>&nbsp;    public Sprite loadSprite(String resource) {
<i class="no-highlight">145</i>&nbsp;        try {
<b class="nc"><i class="no-highlight">146</i>&nbsp;            return super.loadSprite(resource);</b>
<b class="nc"><i class="no-highlight">147</i>&nbsp;        } catch (IOException e) {</b>
<b class="nc"><i class="no-highlight">148</i>&nbsp;            throw new PacmanConfigurationException(&quot;Unable to load sprite: &quot; + resource, e);</b>
<i class="no-highlight">149</i>&nbsp;        }
<i class="no-highlight">150</i>&nbsp;    }
<i class="no-highlight">151</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
